import { Post, Provide, Body, ALL, Inject } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';

import { MallCategoryEntity } from '../entity/category';
import { MallCategoryService } from '../service/category';

/**
 * Todo：更新、删除分类的情况有点复杂 -- 应该同等修改后代分类、以及叶子分类下的所有商品的 categoryId？
 * 或者暂不开放 update、delete 的操作？
 */
@Provide()
@CoolController({
  prefix: '/mall/category',
  api: ['add', 'update', 'delete', 'info', 'list', 'page'],
  entity: MallCategoryEntity,
})
export class MallCategoryController extends BaseController {
  @Inject()
  mallCategoryService: MallCategoryService;

  @Post('/initialize')
  async initialize(@Body(ALL) params: any) {
    // console.log(params);
    await this.mallCategoryService.initialize(params);
    this.ok();
  }
}
